<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" import="com.zzty.taskapp.entity.User"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet"
	href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script
	src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZZTY</title>
<!-- BOOTSTRAP STYLES-->
<link href="../css/bootstrap.css" rel="stylesheet" />

<!-- CUSTOM STYLES-->
<link href="../css/custom.css" rel="stylesheet" />
</head>

<script type="text/javascript">
	function fileChange(target) {
		//检测上传文件的类型 

		var filetypes = ".txt";
		var filepath = target.value;
		if (filepath) {
			var isnext = false;
			var fileend = filepath.substring(filepath.indexOf("."));
			if (fileend == filetypes) {
				isnext = true;
			}
			if (!isnext) {
				alert("不接受此文件类型！");
				target.value = "";
				return false;
			}
		} else {
			return false;
		}
	}
	function getTime() {
		var date = new Date().toLocaleString();
		document.getElementById("time1").value = date;
	}

	var startTime;
	function startOnClick() {

		//document.getElementById("start").style.display = "none";
		//document.getElementById("question").style.display = "block";
		//document.getElementById("operation").value = "judge";
		ajaxCall("post", "../TeamExamTransationServlet", startPage);

	}
	function startPage(result) {

		if (result == "无法开始") {
			alert(result);
		}

		else {
			document.getElementById("start").style.display = "none";
			document.getElementById("question").style.display = "block";
			//alert(result);
			var obj = JSON.parse(result);

			document.getElementById("company").value = obj.teamerId;
			document.getElementById("tarea1").value = obj.question;
			var count = obj.leftTime;
			var strs = new Array();
			strs = count.split("_");
			document.getElementById("t_h").innerHTML = strs[0];
			document.getElementById("t_m").innerHTML = strs[1];
			document.getElementById("t_s").innerHTML = strs[2];
			setInterval(getTime, 1000);
			setInterval(refreshCount, 1000);
		}
	}
	function updateStartTime(result) {

		var count = result;
		var strs = new Array();
		strs = count.split("_");
		document.getElementById("t_h").innerHTML = strs[0];
		document.getElementById("t_m").innerHTML = strs[1];
		document.getElementById("t_s").innerHTML = strs[2];
		document.getElementById("operation").value = "showTeam";
		ajaxCall("Post", "../TeamExamTransationServlet", showTeam);
		//document.getElementById("operation").value = "putQuestion";
		//ajaxCall("Post", "../TeamExamServlet", showInTarea);
		setInterval(refreshCount, 1000);
	}
	function showTeam(result) {
		document.getElementById("company").value = result;
		document.getElementById("operation").value = "putQuestion";
		ajaxCall("Post", "../TeamExamTransationServlet", showInTarea);
	}
	var flag = 0;

	function submitFile() {
		//document.getElementById("operation").value = "updateTotalTime";
		//ajaxCall("Post", "../TeamExamTransationServlet", updateTotalTime);
		//if (flag == 1) {
		//	return;
		//}
		document.getElementById("form1").submit();

	}

	function uploadFile(result) {

	}

	function refreshCount() {
		if (document.getElementById("t_h").innerHTML == "已") {
			return;
		}
		var hour = document.getElementById("t_h").innerHTML.charAt(0);
		var minute = document.getElementById("t_m").innerHTML.charAt(0)
				+ document.getElementById("t_m").innerHTML.charAt(1);
		var second = document.getElementById("t_s").innerHTML.charAt(0)
				+ document.getElementById("t_s").innerHTML.charAt(1);

		var t = (hour * 3600) + (minute * 60) + (second * 1) - 1;
		if (t == 300) {
			alert("剩余时间还有五分钟");
		}
		if (t <= 0) {
			document.getElementById("t_h").innerHTML = "已";
			document.getElementById("t_m").innerHTML = "结";
			document.getElementById("t_s").innerHTML = "束";
		} else {
			var h = Math.floor(t / 60 / 60 % 24);
			var m = Math.floor(t / 60 % 60);
			var s = Math.floor(t % 60);

			document.getElementById("t_h").innerHTML = h + "时";
			if (m < 10) {
				m = "0" + m;
			}
			if (s < 10) {
				s = "0" + s;
			}
			document.getElementById("t_m").innerHTML = m + "分";
			document.getElementById("t_s").innerHTML = s + "秒";
		}
	}

	function ajaxCall(method, url, callBackFunction) {

		var httprequest = new XMLHttpRequest();
		httprequest.onreadystatechange = function() {
			if (httprequest.readyState == 4 && httprequest.status == 200) {
				callBackFunction(httprequest.responseText);
			}
		}
		httprequest.open(method, url, true);
		httprequest.setRequestHeader("X-Requested-With", "AJAX");
		httprequest.send(document.getElementById("operation").value);
	}

	function showInTarea(result) {
		document.getElementById("tarea1").value = result;
	}
	function judgeUploadButton() {
		if (document.getElementById("exampleInputFile").value != "") {
			document.getElementById("b1").value = "提交";
			document.getElementById("b1").disabled = "";
		} else {
			document.getElementById("b1").value = "请选择文件";
			document.getElementById("b1").disabled = "disabled";
		}
	}
	setInterval(judgeUploadButton, 0);

	// 	function startTime(){
	// 		startTime = new Date('2017/5/29 19:00:00');
	// 	}

	// 	function teambegin() {
	// 		var NowTime = new Date();
	// 		document.getElementById("question").style.display = "";
	// 		document.getElementById("start").style.display = "none";		
	// 		s();

	// 	}

	// 	function s() {
	// 		timeStr = new Date().toLocaleString();
	// 		document.getElementById("time1").value = timeStr;

	// 	}
	// 	setInterval(s, 1000);
	// 		function getStartTime(){

	// 	}
	// 	function getRTime(){ 

	// 		startTime();

	// 		var NowTime = new Date(); 
	// 		var t = startTime.getTime()-NowTime.getTime()+2*60*60*1000; 		
	// // 		var EndTime= new Date('2014/10/23 10:00:00'); //截止时间 
	// // 		var NowTime = new Date(); 
	// // 		var t =EndTime.getTime() - NowTime.getTime(); 		 
	// 		var d=Math.floor(t/1000/60/60/24); 
	// 		var h=Math.floor(t/1000/60/60%24); 
	// 		var m=Math.floor(t/1000/60%60); 
	// 		var s=Math.floor(t/1000%60); 		 
	// 		document.getElementById("t_d").innerHTML = d + "天"; 
	// 		document.getElementById("t_h").innerHTML = h + "时"; 
	// 		document.getElementById("t_m").innerHTML = m + "分"; 
	// 		document.getElementById("t_s").innerHTML = s + "秒"; 
	// 		} 
	// 	setInterval(getRTime,0);
<%User user = (User) request.getSession().getAttribute("user");
			String img = (String) user.getImg();%>
	
</script>
<head>

<meta charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZZTY</title>
<!-- BOOTSTRAP STYLES-->
<link href="../css/bootstrap.css" rel="stylesheet" />

<!-- CUSTOM STYLES-->
<link href="../css/custom.css" rel="stylesheet" />
</head>
<body>
	<div id="wrapper">
		<nav class="navbar navbar-default navbar-cls-top " role="navigation"
			style="margin-bottom: 0">
			<div class="navbar-header">
				<!--                 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse"> -->
				<!--                     <span class="sr-only">Toggle navigation</span> -->
				<!--                     <span class="icon-bar"></span> -->
				<!--                     <span class="icon-bar"></span> -->
				<!--                     <span class="icon-bar"></span> -->
				<!--                 </button> -->
				<a class="navbar-brand">自在天原</a>
			</div>
			<div
				style="color: white; padding: 15px 50px 5px 50px; float: right; font-size: 16px;">
				<form action="../loginOut.jsp" method="post">
					<button type="submit" class="btn btn-danger">注销</ button>






					
				</form>
			</div>
		</nav>
		<!-- /. NAV TOP  -->
		<nav class="navbar-default navbar-side" role="navigation">
			<div class="sidebar-collapse">
				<ul class="nav" id="main-menu">
					<li class="text-center"><img src="<%=img%>"
						class="user-image img-responsive" /></li>


					<li><a href="../index.jsp"><i
							class="fa fa-dashboard fa-3x"></i> 主页</a></li>
					<li><a href="UserInfo.jsp"><i class="fa fa-table fa-3x"></i>
							个人信息</a></li>
					<li><a href="SelfExam.jsp"><i class="fa fa-desktop fa-3x"></i>
							今日竞赛</a></li>
					<li><a href="TeamExam.jsp"><i class="fa fa-qrcode fa-3x"></i>
							今日结对</a></li>
					<li><a href="History.jsp"><i
							class="fa fa-bar-chart-o fa-3x"></i> 历史记录</a></li>

					<li><a href="ChangePassword.jsp"><i
							class="fa fa-edit fa-3x"></i> 密码修改 </a></li>


				</ul>

			</div>

		</nav>
		<!-- /. NAV SIDE  -->
		<div id="page-wrapper">
			<div id="page-inner">
				<div class="row">
					<div class="col-md-12">
						<h2>结对竞赛</h2>
						<h5></h5>

					</div>
				</div>
				<!-- /. ROW  -->
				<hr />
				<div class="container" id="question" style="display: none">
					<div class="container">
						<div class="row clearfix">
							<div class="col-md-6 column">
								<div class="row clearfix">
									<div class="col-md-12 column">
										<textarea id="tarea1" rows="30" cols="70" disabled>
									</textarea>
									</div>
								</div>
							</div>
							<div class="col-md-6 column">
								<h2>
									<span>你的队友为<input type="text" id="company"
										style="border: 0px; background: none;" disabled></input></span>
								</h2>
								<div style="padding: 100px 0px 10px;">
									<div>
										<h1>
											<span class="label label-info">当前时间</span><span
												class="label label-info"><input type="text"
												id="time1" style="border: 0px; background: none;" disabled></input></span>

										</h1>
									</div>
									<div>
										<h1>

											<div class="col-sm-offset-0 col-sm-12">
												<h3>
													<div id="CountMsg" class="HotDate">
														<span class="label label-info" id="t_d">00天</span> <span
															class="label label-info" id="t_h">00时</span> <span
															class="label label-info" id="t_m">00分</span> <span
															class="label label-info" id="t_s">00秒</span>
													</div>
												</h3>
											</div>
											<!-- 											<span class="label label-info">剩余时间</span><span -->
											<!-- 												class="label label-info"><input type="text" id="time2" -->
											<!-- 												style="border: 0px; background: none;" disabled></input></span> -->
										</h1>
									</div>
								</div>
								<!-- 								<div style="padding: 300px 0px 10px;"> -->
								<!-- 									<div class="form-group"> -->
								<!-- 										<label for="exampleInputFile">作业上传</label><input type="file" -->
								<!-- 											id="exampleInputFile" /> -->

								<!-- 									</div> -->
								<!-- 								</div> -->
								<div style="padding: 100px 0px 10px;">
									<div class="col-md-6 column">
										<form id="form1" role="form"
											action="../TeamExamTransationServlet" method="post"
											enctype="multipart/form-data">
											<div class="form-group">
												<label for="exampleInputFile">文件上传</label><input type="file"
													id="exampleInputFile" name="filename"
													onchange="fileChange(this);" />
												<p class="help-block"></p>
											</div>
											<button type="button" class="btn btn-default" id="b1"
												onclick="submitFile()">提交</button>
											<div>
												<input id="operation" style="display: none;"></input>
											</div>
										</form>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div style="padding: 300px 0px 10px;">
					<div class="container">
						<div class="row clearfix">
							<div class="col-md-4 column"></div>
							<div class="col-md-4 column">

								<button id="start" type="button"
									class="btn-block btn-lg btn-primary" onclick="startOnClick();">开始</button>
								<!-- btn disabled  -->


							</div>
							<div class="col-md-4 column"></div>
						</div>
					</div>
				</div>
			</div>
			<!-- /. PAGE INNER  -->
		</div>


		<!-- /. PAGE WRAPPER  -->
	</div>
	<!-- /. WRAPPER  -->
	<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
	<!-- JQUERY SCRIPTS -->
	<script src="../js/jquery-1.10.2.js"></script>
	<!-- BOOTSTRAP SCRIPTS -->
	<script src="../js/bootstrap.min.js"></script>
	<!-- METISMENU SCRIPTS -->
	<script src="../js/jquery.metisMenu.js"></script>
</body>
</html>
